Project Detail

Anime Face GAN — DCGAN on 63,000 Training Images

A Deep Convolutional GAN trained on 63,000 anime face images at 64x64 pixels. The generator
learns to produce anime faces from random noise vectors; the discriminator learns to distinguish
real from generated images. Both networks improve through adversarial training until the generator
produces convincing faces the discriminator cannot reliably identify as fake.

The architecture follows the DCGAN paper: transposed convolutions for upsampling in the generator,
strided convolutions for downsampling in the discriminator, BatchNormalization throughout,
LeakyReLU activations, and Adam with BETA_1=0.5. Training ran on Google Colab T4 GPU (free tier),
with checkpoints saved to Google Drive every 10 epochs.

The trained checkpoint is exported to ONNX for serving. ONNX Runtime is ~10MB vs TensorFlow's
~500MB, eliminating cold-start overhead. Inference is deployed on Hugging Face Spaces, which runs
the Docker container continuously with no CPU quota.

The demo includes latent space interpolation: a smooth morphing sequence between two randomly
chosen faces that demonstrates the generator has learned a continuous, structured latent space
rather than memorising training images.

Ai-ml deep-learning neural-network computer-vision deployment REST-API docker CI-CD jupyter web-app generative-ai hugging-face

Quick Facts

Tech:
Python TensorFlow Keras DCGAN ONNX Runtime NumPy Matplotlib Pillow FastAPI Uvicorn Docker Google Colab T4 GPU Hugging Face Spaces GitHub Actions pytest

Overview

Problem

Proving the GAN architecture claimed in the CV with working portfolio evidence. Demonstrates the full ML workflow — cloud GPU training, model export, containerised inference deployment.

Solution

DCGAN with asymmetric learning rates (D=0.0001, G=0.0002) and label smoothing to delay discriminator dominance. Trained on Colab T4 GPU with Drive checkpointing. Trained checkpoint exported to ONNX and committed for zero-retraining inference deployment on Hugging Face Spaces.

Challenges

GAN training instability — mode collapse, discriminator dominance, and oscillating losses are all failure modes addressed by specific architectural choices. Colab auto-save corrupts the portfolio notebook by scrambling cell types — solved by separating training into a dedicated colab_train.ipynb so Colab never touches the main notebook. The Kaggle dataset contains a small number of corrupt image files that crash PIL on load — handled by wrapping each file open in a try/except and skipping bad files. Azure App Service F1's 60 CPU-minute/day quota was exhausted by cold starts — moved to Hugging Face Spaces for cost reasons.

Results / Metrics

Two training runs on Google Colab T4 GPU (100 epochs each). Baseline (equal learning rates) showed discriminator dominance by epoch 20 — D loss near 0, G loss rising to 5. v2 run with LEARNING_RATE_D=0.0001 and label smoothing=0.9 kept training competitive through epoch ~40 (D ~0.92, G ~1.78). Best face quality in epoch 30–60 checkpoints. No mode collapse — 16 distinct faces in every sample grid. Latent space interpolation produces smooth morphing between faces. Late-epoch D dominance remains (D ~0.59, G ~3.21 at epoch 100) — further improvement possible with a full 63,000-image dataset run.

Screenshots

Click to enlarge.

Click to enlarge.

Videos